package com.pd.backend.service.impl;

import com.pd.backend.entity.PdDriverJob;
import com.pd.backend.dao.PdDriverJobDao;
import com.pd.backend.service.PdDriverJobService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 司机作业单(PdDriverJob)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:33
 */
@Service("pdDriverJobService")
public class PdDriverJobServiceImpl implements PdDriverJobService {
    @Resource
    private PdDriverJobDao pdDriverJobDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdDriverJob queryById(String id) {
        return this.pdDriverJobDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdDriverJob 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdDriverJob> queryByPage(PdDriverJob pdDriverJob, PageRequest pageRequest) {
        long total = this.pdDriverJobDao.count(pdDriverJob);
        return new PageImpl<>(this.pdDriverJobDao.queryAllByLimit(pdDriverJob, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdDriverJob 实例对象
     * @return 实例对象
     */
    @Override
    public PdDriverJob insert(PdDriverJob pdDriverJob) {
        this.pdDriverJobDao.insert(pdDriverJob);
        return pdDriverJob;
    }

    /**
     * 修改数据
     *
     * @param pdDriverJob 实例对象
     * @return 实例对象
     */
    @Override
    public PdDriverJob update(PdDriverJob pdDriverJob) {
        this.pdDriverJobDao.update(pdDriverJob);
        return this.queryById(pdDriverJob.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdDriverJobDao.deleteById(id) > 0;
    }
}
